home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
StaticTView.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-21
|
7KB
|
251 lines
#ifndef StaticTView_First
#ifdef __GNUG__
//pragma once
#pragma interface
#endif
#define StaticTView_First
#include "Text.h"
#include "Mark.h"
#include "ObjArray.h"
#include "View.h"
class TextFormatter;
class TextPainter;
enum TViewAlign { // alignment of the view
eTViewLeft,
eTViewRight,
eTViewCenter
};
enum TextViewFlags {
eTextViewNone = 0,
eTextViewReadOnly = BIT(eViewLast+1), // disable text modifications
eTextViewInvis = BIT(eViewLast+2), // show invisible characters
eTextWantFindFocus = BIT(eViewLast+3), // text view wants find focus
eTextViewNoBatch = BIT(eViewLast+4), // do not batch characters
eTextViewModified = BIT(eViewLast+5), // view size modified
eTextViewDragAndDrop= BIT(eViewLast+6), // enable drag&drop
eTextViewNoClip = BIT(eViewLast+7), // clip at inner rectangle
eTextViewLast = eViewLast+6,
eTextViewDefault = eVObjEnabled
};
extern Rectangle gFitRect;
const bool cWordWrap= TRUE,
cNoWordWrap= !cWordWrap,
cShowInvisibles= TRUE,
cHideInvisibles= !cShowInvisibles,
cRevealTop= TRUE,
cDoNotRevealTop= FALSE;
const int cSizeVariable= -1,
cFit= cSizeVariable;
//---- StaticTextView -------------------------------------------------------
class StaticTextView: public View {
public:
MetaDef(StaticTextView);
StaticTextView(
EvtHandler *eh, Rectangle r, Text *t,
bool wrap= cWordWrap,
TextViewFlags= eTextViewDefault,
Point border= gBorder,
TViewAlign m= eTViewLeft,
int id= cIdNone
); // if contentRect.extent.y is set to cSizeVariable
// extent.y is adapted to extent of largest text line
~StaticTextView();
//---- rendering
void PrintAdorn(Rectangle, int gPageNo);
void Draw(Rectangle);
//---- composing
virtual void Repair(int from, int to, bool redraw);
virtual void RepairAll(); // reformat and redisplay whole text
virtual void InvalidateRange(int from, int to);
virtual void InvalidateRange(int from, Point fp, int to, Point tp);
virtual Text *SetText(Text*, bool scroll= cRevealTop); // returns old text
void SetFormatter(TextFormatter *f);
void SetPainter(TextPainter *tp);
void SetPager(TextPager *tp);
virtual void SetString(byte *str, int len= -1);
Text *GetText();
//---- acessing
virtual void SetFont(Font *fd);
TViewAlign GetAlignment()
{ return align; }
void SetAlign(TViewAlign);
void ShowInvisibles(bool);
bool GetShowInvis();
void SetNoBatch(bool);
bool GetNoBatch();
void SetWordWrap(bool m);
bool GetWordWrap();
bool Empty();
int Lines();
int NumberOfLines();
//---- mapping
virtual void PointToPoint(
Point p, Point *viewPos, int *lineNo, int *CharNo, bool relative= TRUE
);
virtual int CharToPoint(
int charNo, int *lineNo,
Point *viewPos, bool relative= TRUE
);
virtual Point LineToPoint(
int line, bool basePoint= FALSE,
bool relative= TRUE
);
virtual int PointToLine(Point p);
virtual int CharToLine(int ch); // return line number of character
Rectangle NextPageBreak(int pageno, Rectangle r);
//---- line structure access
LineMark *MarkAtLine(int i);
int StartLine(int l);
int EndLine(int l);
int LineHeight(int l);
int BaseHeight(int l);
//---- size managment
// adapt view size to the extension of text if wrap is set to TRUE only
// the height is changed
void SetExtent(Point p); // (reformats text)
Metric GetMinSize();
Point GetInnerOrigin();
Point GetInnerExtent();
void SetBorder(Point newBorder);
Point GetBorder();
//----- client marks
void AddMark(Mark *);
Mark *RemoveMark(Mark *);
Iterator *GetMarkIter();
MarkList *GetMarkList();
//----- debugging
void InspectorId(char *buf, int sz);
void CollectParts(Collection*);
//----- generic methods
char *AsString();
OStream& PrintOn(OStream&);
IStream& ReadFrom(IStream&);
void Dump();
void ClassInvariant();
//---- static methods
static Metric MeasureText(char *txt, Font* fd, int minwidth, int nlines= 1);
static void DrawBoxedText(Rectangle r, char *txt, Font*, Ink *ink, bool wrap);
protected:
Text *text; // shown text
class TextFormatter *formatter; // formatter
class TextPainter *painter; // text painter/mapper
class TextPager *pager; // break view into pages
TViewAlign align; // view alignment
bool wrap; // break line at view boundary
bool drawViewBorder;
bool horExtend;
Point border; // border around the text
int nLines; // number of lines
ObjArray *lines; // array of line marks, grows dynamically
MarkList *marks;
int cline; // line and position map cache
int cYPosition;
//----
void Init(
Rectangle, Text*, bool wrap, TextViewFlags, Point, TViewAlign
);
int UpdateView(
int from, int to, int n, ObjArray *newLines, bool redraw
);
void UpdateComposition(int from, int to, int n, ObjArray *newLines);
void UpdateExtent(int dy);
void InvalidateDiff(Point newExtent, Point newOrigin);
int AlignView(int nexExtent);
void SwapRange(int &a, int &b);
virtual void DrawLine(
Point p,int line,Rectangle lineRect,
Rectangle clip
);
};
//---- inlines
inline int StaticTextView::Lines()
{
return nLines;
}
inline int StaticTextView::NumberOfLines()
{
return Lines();
}
inline Text *StaticTextView::GetText()
{
return text;
}
inline bool StaticTextView::Empty()
{
return text->Size() == 0;
}
inline LineMark *StaticTextView::MarkAtLine(int i)
{
return (LineMark*)(*lines)[i];
}
inline int StaticTextView::StartLine(int l)
{
return MarkAtLine(l)->pos;
}
inline int StaticTextView::EndLine(int l)
{
return MarkAtLine(l)->pos + MarkAtLine(l)->len;
}
inline Point StaticTextView::GetInnerOrigin()
{
return contentRect.origin+border;
}
inline Point StaticTextView::GetInnerExtent()
{
return contentRect.extent-2*border;
}
inline void StaticTextView::SetBorder(Point newBorder)
{
border= newBorder;
}
inline Point StaticTextView::GetBorder()
{
return border;
}
#endif